'use strict';

import { basicAction } from '@peace/utils';
import { ApiTable } from '$utils';

// 获取软著列表（分页）
export function getSoftwareCopyrightList(params) {
  return dispatch => basicAction({
    type: 'get',
    dispatch: dispatch,
    actionType: 'GET_SOFTWARE_COPYRIGHT_LIST',
    url: `${ApiTable.getSoftwareCopyrightList}`,
    query: params,
    msg: { error: '获取软著列表失败' },
    reducer: { name: 'softwareCopyrightList' }
  });
}
// 新增软著
export function createSoftwareCopyright(data) {
  return dispatch => basicAction({
    type: 'post',
    dispatch: dispatch,
    actionType: 'CREATE_SOFTWARE_COPYRIGHT',
    url: `${ApiTable.createSoftwareCopyright}`,
    data: data,
    msg: { error: '保存软著信息失败' },
    reducer: { name: 'createSoftwareCopyrightResult' }
  });
}
// 编辑软著
export function editSoftwareCopyright(id, data) {
  return dispatch => basicAction({
    type: 'put',
    dispatch: dispatch,
    actionType: 'EDIT_SOFTWARE_COPYRIGHT',
    url: `${ApiTable.editSoftwareCopyright.replace(':id', id)}`,
    data: data,
    msg: { error: '保存软著信息失败' },
    reducer: { name: 'editSoftwareCopyrightResult' }
  });
}

// 删除软著
export function deleteSoftwareCopyright(id) {
  return dispatch => basicAction({
    type: 'delete',
    dispatch: dispatch,
    actionType: 'DELETE_SOFTWARE_COPYRIGHT',
    url: `${ApiTable.deleteSoftwareCopyright.replace(':id', id)}`,
    msg: { error: '删除软著失败' },
    reducer: { name: 'deleteSoftwareCopyrightResult' }
  });
}

// 导入软著数据
export function importSoftwareCopyright(formData) {
  return dispatch => basicAction({
    type: 'post',
    dispatch: dispatch,
    actionType: 'IMPORT_SOFTWARE_COPYRIGHT',
    url: `${ApiTable.importSoftwareCopyright}`,
    data: formData,
    msg: { error: '导入软著数据失败' },
    reducer: { name: 'importSoftwareCopyrightResult' }
  });
}

// 导出软著数据
export function exportSoftwareCopyright(params) {
  return dispatch => basicAction({
    type: 'get',
    dispatch: dispatch,
    actionType: 'EXPORT_SOFTWARE_COPYRIGHT',
    url: `${ApiTable.exportSoftwareCopyright}`,
    query: params,
    msg: { error: '导出软著数据失败' },
    reducer: { name: 'exportSoftwareCopyrightResult' }
  });
}

// 获取软著导入模板
export function getSoftwareCopyrightTemplate() {
  return dispatch => basicAction({
    type: 'get',
    dispatch: dispatch,
    actionType: 'GET_SOFTWARE_COPYRIGHT_TEMPLATE',
    url: `${ApiTable.getSoftwareCopyrightTemplate}`,
    msg: { error: '获取软著导入模板失败' },
    reducer: { name: 'softwareCopyrightTemplate' }
  });
} 